$('.head-content .right img:first').click(function(){
    location.href="../htm/shopp.html";
})
// 设置html字体
$(window).resize(function () {
    var width = $(window).width();
    if (width > 320 && width < 750) {
        var font = 100 / 750 * width;
        $('html').css('fontSize', font + 'px')
    }
})
$(window).resize();


(function () {
    var mySwiper = new Swiper('.swiper-container', {
        loop: true, // 循环模式选项

        autoplay: true,
        autoplay: {
            delay: 3000,//1秒切换一次
        },
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
            // bulletClass:'bottom:1px'
        },

    })
})();

(function () {
    for (var i = 0; i < homeNav.length; i++) {
        $(`<div class="home-nav-itm">
        <img src = '${homeNav[i].img}'>
        <p>${homeNav[i].tet}</p>
        </div>`).appendTo('.home-nav')

    }
})();


// 点击跳转个人中心
(function () {
    // 点击跳转个人中心
    $('.head-content .right').on('click', '.jump', function (e) {
        e.preventDefault();
        location.href = './html/personal.html'
    })
    // 点击跳转分类
    $('.head-content .left-classify').click(function (e) {
        e.preventDefault();
        location.href = './html/classify.html'
    })
    // 点击跳转百联卡
    $('.home-nav').on('click', '.home-nav-itm:nth-of-type(7)', function (e) {
        console.log(12)
        e.preventDefault();
        location.href = './html/cart.html'
    })
    $('.car').on('click',function(){
        location.href = './html/car.html'
    })
    $('.home-nav .home-nav-itm').eq(0).on('click',function(){
        location.href = './html/babai.html';
    })
    $('.home-nav .home-nav-itm').eq(1).on('click',function(){
        location.href = './html/flash.html';
    })
    $('.home-nav .home-nav-itm').eq(3).on('click',function(){
        location.href = './html/ppt.html';
    })
    $('.home-nav .home-nav-itm').eq(4).on('click',function(){
        location.href = './html/laikuang.html';
    })
    $('.home-nav .home-nav-itm').eq(5).on('click',function(){
        location.href = './html/qqg.html';
    })
  
    $('.home-nav .home-nav-itm').eq(7).on('click',function(){
        location.href = './html/bailianlinquan.html';
    })
    $('.see-more').eq(0).click(function(){
        location.href = './html/jrbkckgd.html';
    })

})();

// 今日爆款
(function () {
    for (var i = 0; i < dayHost.length; i++) {
        $(`<div class="ovfs-item">
    <div>
        <div class="product-img">
            <div class="tag">
            </div>
            <img src='${dayHost[i].url}' alt="">
            <div class="price">${dayHost[i].pic}</div>
            <div class="reference">${dayHost[i].cpic}
            </div>
        </div>
    </div>
</div>`).appendTo('.day-host .product-list')
    }
})();


// 拼团
(function () {
    for (var i = 0; i < pinTuan.length; i++) {
        $(`<div class="pinTuan-content">
    <div class="item-left">
        <img src="${pinTuan[i].url}" alt="">
    </div>
    <div class="right">
        <div class="group-title">${pinTuan[i].groupTitle}</div>
        <div class="middle">${pinTuan[i].middle}</div>
        <div class="open-group">${pinTuan[i].openGroup}</div>
        <div class="bottom">${pinTuan[i].bottom}</div>
    </div>
</div>`).appendTo(".pinTuan>.pintuan-list")
    };
})();


// 好货排行榜
(function () {
    $.get("./php/rank.php", function (res) {
        let data = JSON.parse(res);
        // console.log(data);
        let html = ``;
        data.forEach(function (item) {
            html += ` 
        <div class="inner-item">
            <div>
                <img src="${item.rankImg}"
                    class="rank-img"> <img src="${item.rankImg2}">
            </div>
            <div class="text">
            ${item.text}
            </div>
        </div>`
        });

        $('.rank-content > .inner').html(html)
    });
})();


// 精选活动
(function () {
    $.get("./php/brand_container.php", function (res) {
        let data = JSON.parse(res);
        // console.log(data);
        let html = ``;
        data.forEach(function (item) {
            html += `
        <div class="item">
            <img src="${item.img}">
            ${item.text}
        </div>`
        })
        $('.brand-container > .inner').html(html)
    });
})();


// 猜你喜欢
(function () {
    $.get("./php/product_list.php", function (res) {
        let data = JSON.parse(res);
        //    console.log(data)
        function ia(j) {
            for (i = j; i < j + 7; i++) {
                // console.log(data[i].img)
                $(`
            <li>
                <div class="product-item">
                    <div>
                        <div class="common-bg lazy-box">
                            <span class="similar">${data[i].tet}</span>
                                <img
                                class="square-lazy"
                                src="${data[i].img}">
                            </div>
                        <div class="desc">${data[i].des}
                        </div>
                        <div class="price flex-m">
                            <div>￥${data[i].pri}</div>
                        </div>
                    </div>
                </div>
            </li>
        `).appendTo('.product-list>ul')
            }
            loz = i
        }
        let loz = 0;
        ia(loz);

        $(window).on('scroll', function () {
            let scrtop = $(window).scrollTop();
            let wh = $(window).height();
            let bh = $("body").height();

            if (scrtop >= 20) {
                $(".home-head").css({ "background": "#fff" });
                $(".midd-seach input").css({ "background": "#f4f4f4" });
                // $(".left-classify").css({color:"#808080"})
            } else {
                $(".home-head").css({ "background": "rgba(0, 0, 0, 0.5)" })
                $(".midd-seach input").css({ "background": "#fff" });
            }

            if (loz > 63) {
                $(".infinite-layer").hide()
                return;
            };
            if (bh - (scrtop + wh) < 10) {
                console.log('到底了')

                ia(loz);
            }
        })

    });
})();

//首页点击商品加入购物车

(function(){
    if(localStorage.getItem('phone')){
        var d=localStorage.getItem('phone');

        $('.product-list').on('click','.product-item',function(){
            var phone=d;
            var shopUrl=$(this).find('img').attr('src');
            var title=$(this).find('.desc').text();
            var price=$(this).find('.price> div >div').eq(0).text();
            $.ajax({
                url:'./php/insertcar.php',
                type:'post',
                dataType:'json',
                data:{phone,shopUrl,title,price},
                success:function(res){
                    console.log(res);
                    if(res.code){
                       location.href="./html/car.html";
                    }else{
                        alert('数据库插入失败');
                        location.href="./html/login.html";
                    }
                }
            })
        })
    }

})();

//播放标签
var flag=true;
$('body').on('click','.right-container',function(){
    if(flag){
        $('video').get(0).play();
        $('video').get(0).webkitRequestFullScreen();
        $('.bofang').hide();
        flag=false;
    }else{
        $('video').get(0).pause();
        $('.bofang').show();
        flag=true;
    }
    
})
